<template>
	<view class="order_detail_or_price_bid">
		<view class="time_left">
			<view class="ctx">剩余时间：{{ timeLeftMins }}</view>
		</view>
		<scroll-view v-if="isBid" class="scroll" scroll-y>
			<view class="bid_main">
				<view class="switch">
					<view class="slider" :class="[currency === 1 ? 'left' : 'right']"></view>
					<view class="text">
						<view :class="{ active: currency === 1 }" @click="currency = 1">人民币</view>
						<view :class="{ active: currency === 2 }" @click="currency = 2">元气</view>
					</view>
				</view>
				<OrderItem v-for="(order, index) in bidList" :key="index" :order="order" />
				<view class="no_more">---没有更多---</view>
			</view>
		</scroll-view>
		<scroll-view v-else class="scroll" scroll-y>
			<view class="order_detail">
				<view class="card">
					<view class="order_nft">
						<image src="http://qiniu.relaverse.cn/icon/nft_placeholder.png" mode="widthFix"></image>
						<view class="order_info">
							<view class="name_price">
								<text>NFT名称</text>
							</view>
							<view class="time name_price">
								<text>2025-02-12 10:08:25</text>
							</view>
						</view>
					</view>
				</view>

				<view class="card">
					<view class="cell">
						<text>购买金额</text>
						<text>￥346</text>
					</view>
					<view class="cell">
						<text>付款钱包</text>
						<text>000000000000000000000</text>
					</view>
				</view>

				<view class="card">
					<view class="title">订单信息</view>
					<view class="cell">
						<text class="light">订单编号</text>
						<view class="dif">
							00000000000000000000
							<image class="copy" src="@/static/market/copy.png" mode="widthFix" @click="copyCode" />
						</view>
					</view>
				</view>

				<view class="card">
					<view class="title">订单状态</view>
					<TimeLine />
				</view>

				<view v-if="order.status === 5" class="buttons">
					<view class="btn cancel">取消购买</view>
					<view class="btn">立即付款</view>
				</view>
                <view v-else-if="order.status === 6" class="buttons">
					<view class="btn cancel">取消寄售</view>
				</view>
                <view v-else-if="order.status === 8" class="buttons">
					<view class="btn">接受出价</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>
<script>
import OrderItem from "./components/order/item.vue";
import TimeLine from "./components/order/timeLine.vue";
export default {
	components: {
		OrderItem,
		TimeLine,
	},
	data() {
		return {
			page: 1,
			currency: 1,
			bidList: [
				{
					status: 8,
					hightest: true,
				},
				{
					status: 8,
					hightest: false,
				},
				{
					status: 8,
					hightest: false,
				},
				{
					status: 8,
					hightest: false,
				},
				{
					status: 8,
					hightest: false,
				},
				{
					status: 8,
					hightest: false,
				},
				{
					status: 8,
					hightest: false,
				},
				{
					status: 8,
					hightest: false,
				},
			],
			timeLeft: 10 * 60,
            order: {
                status: 8,
            }
		};
	},

	computed: {
		isBid() {
			return this.page == 2;
		},

		timeLeftMins() {
			return `${`0${Math.floor(this.timeLeft / 60)}`.slice(-2)}:${`0${this.timeLeft % 60}`.slice(-2)}`;
		},
	},

	onLoad(option) {
		console.log("order detail onload", option);
		this.page = option.page;

		if (this.page == 2) {
			uni.setNavigationBarTitle({
				title: "所有出价",
			});
		} else {
			uni.setNavigationBarTitle({
				title: "订单详情",
			});
		}
	},

	methods: {
		copyCode() {
			uni.setClipboardData({
				data: "478445d6f4dsa65f4ads6f5asd",
				success: function () {
					uni.showToast({
						title: "复制成功",
						icon: "none",
						duration: 2000,
					});
				},
			});
		},
	},
};
</script>
<style lang="scss" scoped>
.order_detail_or_price_bid {
	width: 100vw;
	height: 100vh;
	padding: 20rpx 40rpx;
	background-color: #f4f4f4;

	.time_left {
		width: 100%;
		height: 52rpx;
		position: relative;

		.ctx {
			position: absolute;
			left: -40rpx;
			top: -20rpx;
			width: 100vw;
			height: 100%;
			background-color: #2359f8;

			color: white;
			text-align: center;
			line-height: 52rpx;
			font-size: 24rpx;
		}
	}

	.scroll {
		width: 100%;
		height: 100%;
		background-color: #f4f4f4;

		.bid_main {
			width: 100%;
			height: max-content;

			.switch {
				width: 216rpx;
				height: 50rpx;
				background-color: #eeeeee;
				border-radius: 26rpx;
				position: relative;
				overflow: hidden;
				margin-bottom: 20rpx;

				.slider {
					width: 50%;
					height: 100%;
					background-color: #2359f8;
					box-shadow: 0px 2rpx 8rpx 0px #00000066;
					border-radius: 26rpx;

					&.left {
						transform: translateX(0);
					}

					&.right {
						transform: translateX(100%);
					}

					transition: transform 0.3s ease;
				}

				.text {
					position: absolute;
					left: 0;
					top: 0;
					width: 100%;
					height: 100%;

					font-size: 24rpx;
					text-align: center;

					display: flex;
					justify-content: space-around;
					align-items: center;

					view {
						flex: 1;
						font-weight: bold;

						color: #999999;

						&.active {
							color: white;
						}
					}
				}
			}

			.no_more {
				font-weight: 400;
				font-size: 24rpx;
				text-align: center;
				margin: 30rpx auto;
				color: #888888;
			}
		}
	}

	.order_detail {
		width: 100%;
		height: max-content;

		.card {
			width: 100%;
			height: max-content;
			border-radius: 20rpx;
			background-color: #fff;
			padding: 20rpx 40rpx;

			margin-bottom: 20rpx;

			.order_nft {
				width: 100%;

				display: flex;
				justify-content: flex-start;
				align-items: center;
				margin-top: 20rpx;

				image {
					width: 100rpx;
					border-radius: 10rpx;
				}

				.order_info {
					width: calc(100% - 100rpx);
					// height: 100rpx;
					margin-left: 22rpx;
					display: flex;
					justify-content: space-between;
					align-items: flex-start;
					flex-direction: column;

					.name_price {
						width: 100%;

						display: flex;
						justify-content: space-between;
						align-items: center;

						font-weight: 500;
						font-size: 32rpx;
						color: black;
					}

					.time {
						font-weight: 500;
						font-size: 24rpx;
						color: #999999;

						.highest {
							color: #2359f8;
						}
					}
				}
			}

			.title {
				font-weight: 500;
				font-size: 28rpx;
				margin-bottom: 20rpx;
			}

			.cell {
				width: 100%;
				height: 40rpx;

				display: flex;
				justify-content: space-between;
				align-items: center;

				color: black;
				font-weight: 500;
				font-size: 24rpx;

				view.dif {
					display: inline-flex;
					align-items: center;
				}

				.light {
					color: #999999;
				}

				.copy {
					width: 28rpx;
					margin-left: 5rpx;
					vertical-align: middle;
				}

				& + .cell {
					margin-top: 20rpx;
				}
			}
		}

		.buttons {
			margin-top: 60rpx;
			width: 100%;
			height: 80rpx;
			padding: 0 40rpx;
            margin-bottom: 20rpx;

			display: flex;
			justify-content: center;
			align-content: center;

			.btn { 
				width: 48%;
				height: 100%;
				border-radius: 20rpx;
				background-color: #2359f8;
				color: white;

				font-weight: bold;
				font-size: 16px;
				line-height: 80rpx;
                
                text-align: center;

				&.cancel {
					color: #999999;
					background-color: #cccccc;
				}

                &:nth-child(2) {
                    margin-left: auto;
                }
			}
		}
	}
}
</style>
